<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta charset="utf-8"/>
		<meta name="viewport" content="width=1000, initial-scale=1.0, maximum-scale=1.0">
		<title>
		</title>
		<link href="{{__PUBLIC__}}/Admin/Flat/dist/css/vendor/bootstrap.min.css" rel="stylesheet">
		
		<link rel="stylesheet" href="{{__PUBLIC__}}/Uploadify/uploadify.css" />
		<script type="text/javascript" src='{{__PUBLIC__}}/jquery-1.7.2.min.js'></script>
		<script type="text/javascript" src='{{__PUBLIC__}}/Uploadify/jquery.uploadify.js'></script>
		<script type="text/javascript" src='{{__PUBLIC__}}/Ueditor/ueditor.config.js'></script>
		<script type="text/javascript" src='{{__PUBLIC__}}/Ueditor/ueditor.all.min.js'></script>

		<script type="text/javascript">
			$(function(){
				$('select[name=category_cid]').change(function(){
//					获得被选中的type_tid
					var type_tid=$(':selected',this).attr('type_tid');
					$('input[name=type_tid]').val(type_tid);
//										alert(type_tid);
					/*//					顶级分类没有类型不需要发送异步
					if(type_tid==0) return;*/
					
//					通过异步发送type_tid获得类型属性
					$.ajax({
//						请求地址
						url:'{{U('ajaxGetAttr')}}',
//						发送数据
						data:{type_tid:type_tid},
						type:'post',
						dataType:'json',
						success:function(phpData){
//							alert(1);
						//							属性
							var attr='';
							var spec='';
							
//							.each(phpData,function(k,v)便利phpData
							$.each(phpData,function(k,v){
								
//								taclass=0是属性不可选择
								if(v.taclass==0){
									attr+='<tr class="info"><td align="right">'+v.taname+'</td><td>';
									attr += '<select name="attr['+v.taid+']" id=""><option value="">请选择</option>';
										$.each(v.tavalue,function(kk,vv){
											attr+='<option value="'+vv+'">'+vv+'</option>'
										});
										attr+='</select></td></tr>';
								}else{
//									否则就是规格
									spec+='<tr class="info"><td>'+v.taname+'</td><td>';
									spec +='<select name="spec['+v.taid+'][value][]"><option value="0">-请选择-</option>';
										$.each(v.tavalue,function(kk,vv){
											spec+='<option value="'+vv+'" >'+vv+'</option>';
										});
										spec +='</select></td>';
										spec +='<td>附加价格：<input type="text" name="spec['+v.taid+'][price][]" value="0" /></td>';
										spec+='<td><span class="add-spec btn btn-success"><i class="icon-plus icon-white"></i>添加规格</span></td>';
										spec+='</tr>';
							
					
								}
							});
//							获得属性规格的所有html代码
							$('#attr').html(attr);
							$('#spec').html(spec);
							
						}
					})
				})
				//				点击增加规格
				$('.add-spec').live('click',function(){
				//					找到父级的tr
					var tr=$(this).parents('tr');
//					alert(tr);
//					克隆
					var trobj=tr.clone();
					$('.add-spec',trobj).removeClass('btn-success add-spec').addClass('btn-danger del-spec').html('<i class="icon-plus icon-white"></i>删除规格');
//					在下一行插入
					tr.after(trobj);
					
				})
//				删除规格
				$('.del-spec').live('click',function(){
					$(this).parents('tr').remove();
				})
				
				
			})
			
			

			  
        </script>
		<style type="text/css">/*去掉uploadify上传按钮的边框*/

			.uploadify-button {
				background-color: transparent;
				border: none;
				padding: 0;
			}
			
			.uploadify:hover .uploadify-button {
				background-color: transparent;
			}
			
			.hide {
				display: none;
			}
			
			body {
				margin-bottom: 100px;
			}
		</style>
	</head>
	<body>
		<!--<table class="table table-hover">-->
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<form action="" method='post' enctype="multipart/form-data">
						{{foreach from="$goodsdata" value="$gv"}}
						
						<fieldset>
							<legend>
								修改商品
							</legend>
							
							<table class='table table-bordered table-hover'>
								<thead>
									<tr>
										<th colspan="2" class="btn btn-primary">
											基本信息
										</th>
									</tr>
								</thead>
								<tbody>
									<tr class="info">
										<td>
											所属分类
										</td>
										<td>
											<select name="category_cid">
												
												{{foreach from="$catedata"value="$cv"}}
												<option value="{{$cv['cid']}}" type_tid="{{$cv['type_tid']}}"{{if value="$cv['cid'] eq $gv['category_cid']"}}selected {{endif}}>
													{{$cv['cname']}}
												</option>
												{{endforeach}}
											</select>
										</td>
									</tr>
									<tr class="info">
										<td>
											所属品牌
										</td>
										<td>
											<select name="brand_bid">
												
												{{foreach from="$branddata"value="$bv"}}
												<option value="{{$bv['bid']}}"{{if value="$bv['bid'] eq $gv['brand_bid']"}}selected {{endif}}>
													{{$bv['bname']}}
												</option>
												{{endforeach}}
											</select>
										</td>
									</tr>
									
									<tr class="info">
										<td>
											商品名称
										</td>
										<td>
											<input type="text" name='gname'value="{{$gv['gname']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											单位
										</td>
										<td>
											<input type="text" name='unit' value="{{$gv['gnumber']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											市价场
										</td>
										<td>
											<input type="text" name='marketprice'value="{{$gv['maketprice']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											商城价
										</td>
										<td>
											<input type="text" name='shopprice'value="{{$gv['shopprice']}}"/>
										</td>
									</tr>
									<tr class="info">
										<td>
											点击次数
										</td>
										<td>
											<input type="text" name='click'value="{{$gv['click']}}"/>
										</td>
									</tr>
									
								</tbody>
							</table>
							
							<p class="btn btn-primary">
								商品属性
							</p>
							
							<table class="table table-bordered table-hover" id='attr' class="info">
								
									{{foreach from="$gattdata" value="$v"}}
									{{if value="$v['taclass']==0"}}
									<tr class="info">
										
									<td align="right">{{$v['taname']}}</td>
									<td>
										<select name="attr[{{$v['typeattribute_taid']}}]" id="">
											{{foreach from="$v['tavalue']" value="$value"}}
											
											<option value="{{$value}}"{{if value="$value eq $v['gavalue']"}} selected{{endif}}>{{$value}}</option>
											{{endforeach}}
											
										</select>
									</td>
									</tr>
									{{endif}}
									{{endforeach}}
								
							</table>
							<p class="btn btn-primary">
								商品规格
							</p>
							
							<table class="table table-bordered table-hover" id='spec'>
								{{foreach from="$gattdata" value="$v"}}
								{{if value="$v['taclass']==1"}}
								
								<tr class="info">
									
									<td>{{$v['taname']}}</td>
									<td>
										<select name="spec[{{$v['taid']}}][value][]">
											{{foreach from="$v['tavalue']" value="$value"}}									
											<option value="{{$value}}" {{if value="$value eq $v['gavalue']"}}selected{{endif}}>{{$value}}</option>	
											{{endforeach}}	
										</select>
									</td>
									<td>附加价格：<input type="text" name="spec[{{$v['taid']}}][addprice][]" value="{{$v['addprice']}}" /></td>
									<td><span class="add-spec btn btn-success"><i class="icon-plus icon-white"></i>添加规格</span></td>
										
									
								</tr>
								{{endif}}
								{{endforeach}}
							</table><br />
							
							
							
							<table class='table table-bordered'>
								<tr>
									<th colspan="3" class="btn btn-primary">
										列表图
									</th>
									
								</tr>
								<tr class="info">
									<td>
										上传图片
									</td>
									
									<script type="text/javascript">
//									
										$(function(){
											$('.close_img').click(function(){
												
													//1.关闭图片，x也消失
													$('.img_tr').remove();
													$('.img_photo').css('display','block');
												
											})
										})
									</script>
									<!--如果有图片显示图片-->
									
									<td class='img_tr'>
										<a href="javascript:;" class="close_img">X</a>
										{{foreach from="$goodsdata" value="$v"}}
										<img src="{{__ROOT__}}/{{$v['pic']}}" alt="" />
										{{endforeach}}
									</td>
									
										<td class="img_photo" style="display:none">
											<div lab="uploadFile">
	    <input id="file" type="file" multiple="true" >
	    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
	    <script type="text/javascript">
	        $(function() {
	            $('#file').uploadify({
	                'formData'     : {//POST数据
	                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
	                },
	                'fileTypeDesc' : '上传文件',//上传描述
	                'fileTypeExts' : '*.jpg;*.png',
	                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
	                'uploader' : '{{U('upload')}}',
	                'buttonText':'选择文件',
	                'fileSizeLimit' : '2000KB',
	                'uploadLimit' : 10,//上传文件数
	                'width':65,
	                'height':25,
	                'successTimeout':10,//等待服务器响应时间
	                'removeTimeout' : 0.2,//成功显示时间
	                'onUploadSuccess' : function(file, data, response) {
						//转为json
	                    data=$.parseJSON(data);
	                    //获得图片地址
	                    var imageUrl = data.url;
	                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='pic' value='"+data.path+"'/></li>";
	                    $("#uploadList ul").prepend(li);
	                }
	            });
	        });
	    </script>
	    <div id="uploadList">
	        <ul>
	
	        </ul>
	    </div>
	</div>	    						
										</td>
								
									
								</tr>
							</table>
							<table class='table table-bordered'>
								<tr>
									<th colspan="3" class="btn btn-primary">
										商品图册
									</th>
								</tr>
								<tr class="info">
									<td>
										上传图片
									</td>
									<script type="text/javascript">
										$(function(){
											$('.img').click(function(){
												$('.aimg').remove();
												$('.pic').css('display','block');
											})
										})
									</script>
									{{foreach from="$goodsdata"value="$v"}}
									<td class='aimg'>
										<a href="javascript:;" class="img">X</a>
										{{foreach from="$detialdata['photo']"value="$vv"}}
										<img src="{{__ROOT__}}/{{$vv}}" alt="" />
										{{endforeach}}
									</td>
									{{endforeach}}
									<td class='pic'style='display:none;'>
									<div lab="uploadFile">
    <input id="file1" type="file" multiple="true">
    <span>类型: *.jpg,*.png 大小: 2000KB 数量: 10</span>
    <script type="text/javascript">
        $(function() {
            $('#file1').uploadify({
                'formData'     : {//POST数据
                    '<?php echo session_name();?>' : '<?php echo session_id();?>',
                },
                'fileTypeDesc' : '上传文件',//上传描述
                'fileTypeExts' : '*.jpg;*.png',
                'swf'      : '{{__PUBLIC__}}/uploadify/uploadify.swf',
                'uploader' : '{{U('Goods/picture')}}',
                'buttonText':'选择文件',
                'fileSizeLimit' : '2000KB',
                'uploadLimit' : 10,//上传文件数
                'width':65,
                'height':25,
                'successTimeout':10,//等待服务器响应时间
                'removeTimeout' : 0.2,//成功显示时间
                'onUploadSuccess' : function(file, data, response) {
					//转为json
                    data=$.parseJSON(data);
                    //获得图片地址
                    var imageUrl = data.url;
                    var li="<li path='"+data.path+"' url='"+data.url+"'><img src='"+imageUrl+"'/><input type='hidden' name='photo[]' value='"+data.path+"'/></li>";
                    $("#uploadList1 ul").prepend(li);
                }
            });
        });
    </script>
    <div id="uploadList1">
        <ul>
			
        </ul>
    </div>
</div>
									</td>
									
								</tr>
							</table>
							
							<table class='table'>
								<tr class="next_show">
									<th class="btn btn-primary">
										售后服务
									</th>
								</tr>
								<tr class=" info">
									<td>
										<textarea name="service" rows="" cols="">{{$detialdata['service']}}</textarea>																		


									</td>
								</tr>
							</table>
							<table class='table'>
								<tr class="next_show">
									<th class="btn btn-primary">
										商品详情
									</th>
								</tr>
								<tr class=" info">
									<td>
											<label for="exampleInputEmail1">文章正文</label>
			<script id="editor" type="text/plain" style="width:100%;height:500px;" name="intro">{{$detialdata['intro']}}</script>
				<script type="text/javascript">
					var ue=UE.getEditor('editor');
				</script>																					


									</td>
								</tr>
							</table>
							<input type="hidden" name='type_tid' value='0'/>
							<!--<input type="hidden" name="auser_auid" />-->
							<input type="submit" value="确认添加" class="btn btn-primary btn-block btn-large" />
						</fieldset>
						{{endforeach}}
					</form>
				</div>
			</div>
		</div>
		<!--</table>-->
	</body>
</html>